package cn.gorit.content.controller;

import cn.gorit.common.enums.ResultEnums;
import cn.gorit.common.lang.Result;
import cn.gorit.content.service.CommentService;
import cn.gorit.entity.content.Comment;
import cn.gorit.entity.content.CommentResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version v1.0
 * @Classname CommentController
 * @Description 评论控制类
 * @Author CodingGorit
 * @Created on 2021/4/3 16:41
 * @IDLE IntelliJ IDEA
 **/
@RestController
@RequestMapping("/api/v1/front/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 添加评论
    @PostMapping
    public Result<Object> addComment(@RequestBody Comment comment) {
        return commentService.save(comment);
    }

    // 修改评论
    @PutMapping
    public Result<Object> updateComment(@RequestBody Comment comment) {
        return commentService.update(comment);
    }

    // 回复评论
    @PostMapping("/response")
    public Result<Object> respComment(@RequestBody CommentResponse response) {
        return commentService.responseComment(response);
    }

    // 查询评论列表
    @GetMapping("/{blogId}")
    public Result<List<Comment>> getCommentByBlogId(@PathVariable("blogId") String blogId) {
        return commentService.getComments(blogId);
    }

    // 删除评论  form 传参，而不是用 JSON 传参
    @DeleteMapping
    public Result deleteComment(@RequestParam(value = "comment_id") String commentId, @RequestParam(required = false,value = "response_id") String responseId)  {
        commentService.delete(commentId, responseId);
        return new Result(ResultEnums.DELETE_SUCCESS.getCode(),ResultEnums.DELETE_SUCCESS.getMsg());
    }

    // 评论点赞

    // 评论点赞
}
